<template>
  <div class='goods-comment'>
    <div class="comment-head">
      <div class="rate">
        <p class="data">
          <span><i>1033</i>人购买</span>
          <span><i>98.3%</i>好评率</span>
        </p>
      </div>
      <div class="tags">
        <dl>
          <dt>大家都在说：</dt>
          <dd>
            <span class="tag-item active">全部评价（999+）</span>
            <span class="tag-item">有图（50）</span>
            <span class="tag-item">保暖性好（864）</span>
            <span class="tag-item">保暖性好（864）</span>
            <span class="tag-item">值得拥有（229）</span>
            <span class="tag-item">快递给力（201）</span>
          </dd>
        </dl>
      </div>
    </div>
    <div class="comment-list">
      <div class="sort">排序：<span class="active">最热</span><span>最新</span></div>
      <ul>
        <li v-for="item in comments" :key="item.id">
          <div class="comment-item">
            <div class="user">
              <img :src="item.avatar" alt="">
              <span>{{item.nickname}}</span>
            </div>
            <div class="body">
              <div class="score">
                <span class="iconfont icon-wjx01" v-for="i in item.score" :key="i+'s'"></span>
                <span class="iconfont icon-wjx02" v-for="i in (5-item.score)" :key="i+'k'"></span>
                <span class="attr">{{item.attrText}}</span>
              </div>
              <div class="text">{{item.content}}</div>
              <div class="image" v-if="item.images&&item.images.length">
                <img @click="item.previewIndex=i" :class="{active:item.previewIndex===i}" v-for="(img,i) in item.images" :key="i" :src="img" alt="">
                <div class="preview" v-if="item.previewIndex!=undefined">
                  <img :src="item.images[item.previewIndex]" alt="">
                  <span @click="item.previewIndex--" class="prev iconfont icon-angle-left" v-if="item.previewIndex!==0"></span>
                  <span @click="item.previewIndex++" class="next iconfont icon-angle-right" v-if="item.previewIndex!==(item.images.length-1)"></span>
                  <span class="close iconfont icon-close-new" @click="item.previewIndex=undefined"></span>
                </div>
              </div>
              <div class="time">
                <span>{{item.createTime}}</span>
                <span class="zan"><i class="iconfont icon-dianzan"></i> {{item.likeCount}}</span>
              </div>
            </div>
          </div>
        </li>
      </ul>
      <!-- 分页 -->
      <xtx-pagination
        style="padding-top:40px"
        :current-page="reqParams.page"
        :page-size="reqParams.pageSzie"
        :total="400"
      >
      </xtx-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'goods-comment',
  data () {
    return {
      total: 400,
      reqParams: {
        page: 1,
        pageSize: 10
      },
      comments: []
    }
  },
  created () {
    for (let i = 0; i < 5; i++) {
      this.comments.push({
        id: '38427843' + i,
        nickname: '兔****m',
        avatar: 'http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/avatar_1.png',
        score: 4,
        createTime: '2020-10-10 10:11:22',
        likeCount: 122,
        attrText: '颜色：黑色 尺码：M',
        content: '网易云app上这款耳机非常不错 新人下载网易云购买这款耳机优惠大 而且耳机🎧确实正品 音质特别好 戴上这款耳机 听音乐看电影效果声音真是太棒了 无线方便 小盒自动充电 最主要是质量好音质棒 想要买耳机的放心拍 音效巴巴滴 老棒了',
        images: [
          'https://yanxuan-item.nosdn.127.net/13b8d8e7da6a36404f2e5cdfa8276082.png',
          'https://yanxuan.nosdn.127.net/cd9cbc4a86bcd99d25af250dec57aa38.jpg',
          'https://yanxuan.nosdn.127.net/cd9cbc4a86bcd99d25af250dec57aa38.jpg',
          'https://yanxuan.nosdn.127.net/cd9cbc4a86bcd99d25af250dec57aa38.jpg',
          'https://yanxuan.nosdn.127.net/cd9cbc4a86bcd99d25af250dec57aa38.jpg',
          'https://yanxuan.nosdn.127.net/f49fb4b463d9469410151f57edd1ac03.jpg'
        ],
        previewIndex: undefined
      })
    }
  }
}
</script>

<style scoped lang='less'>
.goods-comment{
  min-height: 400px;
  padding-top: 25px;
  .comment-head {
    display: flex;
    .rate {
      width: 340px;
      padding: 0 25px;
      border-right: 1px solid #f5f5f5;
      .name {
        font-size: 20px;
      }
      .desc {
        color: #999;
        padding-top: 5px;
        height: 43px;
      }
      .data {
        display: flex;
        justify-content: space-around;
        padding-top: 30px;
        color: #999;
        text-align: center;
        i {
          font-size: 32px;
          color: @priceColor;
          padding-right: 5px;
          display: block;
        }
      }
    }
    .tags {
      flex: 1;
      dl {
        display: flex;
        dt {
          width: 100px;
          font-weight: bold;
          text-align: right;
          line-height: 42px;
        }
        dd {
          flex: 1;
          display: flex;
          flex-wrap: wrap;
          .tag-item {
            margin-left: 20px;
            margin-bottom: 20px;
            width: 130px;
            height: 42px;
            border: 1px solid #e4e4e4;
            background: #f5f5f5;
            text-align: center;
            line-height: 40px;
            border-radius: 4px;
            cursor: pointer;
            color: #999;
            &:hover {
              border-color: @xtxColor;
              color: @xtxColor;
              background: #fff;
            }
            &.active {
              border-color: @xtxColor;
              background: @xtxColor;
              color: #fff;
            }
          }
        }
      }
    }
  }
  .comment-list {
    padding: 25px;
    .sort {
      height: 60px;
      line-height: 60px;
      padding: 0 20px;
      border-top: 1px solid #f5f5f5;
      border-bottom: 1px solid #f5f5f5;
      span {
        padding-left: 40px;
        cursor: pointer;
        &.active,&:hover {
          color: @xtxColor;
        }
      }
    }
    .comment-item {
      display: flex;
      padding: 25px 10px;
      border-bottom: 1px solid #f5f5f5;
      .user {
        width: 160px;
        img {
          width: 40px;
          height: 40px;
          border-radius: 50%;
          overflow: hidden;
        }
        span {
          padding-left: 10px;
          color: #666;
        }
      }
      .body {
        flex: 1;
        .score {
          line-height: 40px;
          .iconfont {
            color: #ff9240;
            padding-right: 3px;
          }
          .attr {
            padding-left: 10px;
            color: #666;
          }
        }
      }
      .text {
        color: #666;
        line-height: 24px;
      }
      .image {
        padding-top: 10px;
        img {
          border: 1px solid #e4e4e4;
          width: 120px;
          height: 120px;
          margin-bottom: 10px;
          margin-right: 10px;
          object-fit: contain;
          &.active {
            border-color: @xtxColor;
          }
        }
        .preview {
          width: 500px;
          height: 500px;
          background: #f5f5f5;
          margin-bottom: 10px;
          position: relative;
          img {
            width: 100%;
            height: 100%;
            object-fit: contain;
            border: none;
            margin: 0;
          }
          &:hover {
            .prev,.next {
              opacity: 1;
            }
          }
          .close {
            width: 30px;
            height: 30px;
            background: rgba(0, 0, 0, 0.3);
            position: absolute;
            right: 0;
            top: 0;
            color: #f5f5f5;
            text-align: center;
            line-height: 30px;
          }
          // 切换按钮
          .prev,.next {
            width: 44px;
            height: 44px;
            line-height: 44px;
            text-align: center;
            border-radius: 50%;
            margin-top: -22px;
            opacity: 0;
            transition: opacity 0.5s;
            background-color: rgba(0, 0, 0, 0.3);
            position: absolute;
            top: 50%;
            color: #f5f5f5;
            font-size: 20px;
            &.prev {
              left: 10px;
            }
            &.next {
              right: 10px;
            }
          }
        }
      }
      .time {
        color: #999;
        display: flex;
        justify-content: space-between;
        .zan {
          cursor: pointer;
          &:active {
            color: @fuzuColor;
          }
        }
      }
    }
  }
}
</style>
